package com.crm.reports;

import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JOptionPane;

import org.apache.log4j.Logger;

import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanArrayDataSource;

import com.crm.beans.QuotParts;

public class JRDeliveryChallan {

	private final static Logger logger=Logger.getLogger(JRDeliveryChallan.class.getName());
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		String refno="KK/CP/1/19-12-2011";
		  Map parameters = new HashMap();
		  parameters.put("challanno", "KK/CP/1/12-09-2012");
		  parameters.put("sonumber", "1234");
		  parameters.put("sodate", "12/06/2011");
		  parameters.put("customer", "THE PURCHASE MANAGER,\n" +
			  		"ELECTRONIC CORPORATION OF INDIA,\n" +
			  		"ECIL POST ,\n" +
			  		"HYDERABAD \n"+
			  		"500072");
		  parameters.put("from", "KK Circuits And Equipments");
		  
		  List<QuotParts> l=new ArrayList<QuotParts>();
		  QuotParts qp=new QuotParts();
		  qp.sno="1";
		  qp.partNo="er1";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		 qp=new QuotParts();
		  qp.sno="2";
		  qp.partNo="er2";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="3";
		  qp.partNo="er3";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="4";
		  qp.partNo="er4";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="5";
		  qp.partNo="er5";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="6";
		  qp.partNo="er6";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="7";
		  qp.partNo="er7";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="8";
		  qp.partNo="er8";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="9";
		  qp.partNo="er9";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="10";
		  qp.partNo="er10";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="11";
		  qp.partNo="er11";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="12";
		  qp.partNo="er12";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="13";
		  qp.partNo="er13";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="14";
		  qp.partNo="er14";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.sno="15";
		  qp.partNo="er15";
		  qp.desc="abcd";
		  qp.qty="10";
		  l.add(qp);
		  
		runReport("D:/work/crmWeb/WebContent/WEB-INF/classes/reports/dc.jasper",refno, parameters, l.toArray());
		
		}

	public static void runReport(String repName,String refno,Map params,Object[] qparts) throws Exception{
		  long start = System.currentTimeMillis();
		  //Preparing parameters
		   
		 JasperPrint print =JasperFillManager.fillReport(repName,params,new JRBeanArrayDataSource(qparts));
		 
		 
		 OutputStream output = new FileOutputStream(new File(" Delivery Challan.pdf"));
		  JasperExportManager.exportReportToPdfStream(print, output); 
		  output.close();
		  //Thread.sleep(2000);
		  Desktop.getDesktop().open(new File(" Delivery Challan.pdf"));
		  
		  System.err.println("Filling time : " + (System.currentTimeMillis() - start));
		
	}
	public static void wordReport(String repName,String refno,Map params,Object[] qparts) throws Exception{
		long start = System.currentTimeMillis();
		//Preparing parameters
		
		JasperPrint print =JasperFillManager.fillReport(repName,params,new JRBeanArrayDataSource(qparts));
		
		
		OutputStream output = new FileOutputStream(new File(" Delivery Challan.pdf"));
		JasperExportManager.exportReportToPdfStream(print, output); 
		output.close();
		//Thread.sleep(2000);
		Desktop.getDesktop().open(new File(" Delivery Challan.pdf"));
		
		System.err.println("Filling time : " + (System.currentTimeMillis() - start));
		
	}
}
